home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 12 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  37 lines

  1. Newsgroups: comp.lang.c
  2. Path: in2.uu.net!iglou!iglou2!quare
  3. From: quare@iglou2.iglou.com (quare)
  4. Subject: Re: strange problem with strcpy()
  5. X-Nntp-Posting-Host: iglou2
  6. Message-ID: <DKGz2u.8rs@iglou.com>
  7. Sender: news@iglou.com (News Administrator)
  8. Organization: IgLou Internet Services (1-800-436-4456)
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. References: <DKFsII.FyJ@iglou.com> <30e62ceb.8255139@ixnews1.ix.netcom.com>
  11. Date: Sun, 31 Dec 1995 21:16:06 GMT
  12.  
  13. n4jvp (n4jvp@ix.netcom.com) wrote:
  14.  
  15. >     Would the problem be that pointer->name is a char * that is
  16. > initialized but not defined? When memory is allocated for data member
  17. > char * name (\0) that is all the memory you have for that data member.
  18. > Doing a strcpy() as you describe might make * name appear to be test.c
  19. > but in memory there is only room for one character, the terminating
  20. > null.
  21. >     Thats my best guess without seeing some code...
  22.  
  23. Don't think so.  Basically I allocate sizeof(struct find_t) * 
  24. number_of_files_in_cwd.  The find_t structure (as defined by Ms-dog) 
  25. contains (for filename storage) char name[14]; (8 chars for filename, one 
  26. for a 'dot' [.] and 3 for the extension.. and of course, 1 for the null).
  27.  
  28. I am dynamically realloc()'ing more space as the need arises (i start out 
  29. with space for 50 files).  If more than 50 files are read in, I realloc() 
  30. for sizeof(struct find_t) * (50 + current_file_count).  The realloc call 
  31. never fails (at least not while I'm debugging it).  I will post the code 
  32. if anyone thinks they might know the problem (it's less than 100 lines).
  33.  
  34. -- 
  35. !quare 
  36.  
  37.